package com.laoniu.service.login;

import com.laoniu.entity.SecurityUser;
import com.laoniu.entity.User;
import com.laoniu.service.sys.UserService;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Objects;

@Service
public class UserDetailServiceImpl  implements UserDetailsService {

    @Resource
    private UserService userService;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        User user = userService.selectByUserName(username);
        if (Objects.isNull(user)){
            throw new UsernameNotFoundException("用户不存在");
        }
        return new SecurityUser(user);
    }


}
